package com.ehotting.edsta.mqbd.signal.netty.handler;

import com.ehotting.eaf.netty.client.TcpClient;
import com.ehotting.eaf.netty.client.TcpClientHelper;
import com.ehotting.eaf.netty.domain.DataAble;
import com.ehotting.edsta.mqbd.signal.api.domain.netty.RegisterRequest;

public class SignalAnalysisTcpClient extends TcpClient {

    private TcpClientHelper tcpClientHelper;

    public void setTcpClientHelper(TcpClientHelper tcpClientHelper) {
        this.tcpClientHelper = tcpClientHelper;
        this.tcpClientHelper.setTcpClient(this);
    }

    @Override
    public void success() {
        logger.info("SignalAnalysisTcpClient connected");
        send(new RegisterRequest());
    }

    @Override
    public void fail() {
        logger.info("SignalAnalysisTcpClient disconnected");
    }

    /**
     * 同步发送
     * @param data
     * @param timeout
     * @param sync
     * @return
     */
    public DataAble request(DataAble data, long timeout, boolean sync){
        return tcpClientHelper.request( data,  timeout,  sync);
    }

    public void request(DataAble data) {
         tcpClientHelper.request(data);
    }

    public DataAble request(DataAble data, boolean sync){
        return tcpClientHelper.request(data,sync);
    }


}
